package com.hxm.meizi.adapter;

import android.support.v4.view.PagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;

import com.hxm.meizi.entity.ImageUrl;
import com.hxm.meizi.util.ImageLoader;

import java.util.ArrayList;

import uk.co.senab.photoview.PhotoView;

/**
 * Created by Hxm on 2017/2/20.
 */

public class ImagePreAdapter extends PagerAdapter {

    private ArrayList<ImageUrl> imageUrls;
    private AppCompatActivity activity;

    public ImagePreAdapter(AppCompatActivity activity, ArrayList<ImageUrl> imageUrls) {
        this.imageUrls = imageUrls;
        this.activity = activity;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        String url = imageUrls.get(position).getUrl();
        PhotoView photoView = new PhotoView(activity);
        ImageLoader.displayImage(activity, url, photoView);
        container.addView(photoView);
        return photoView;
    }

    @Override
    public int getCount() {
        return imageUrls.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}
